//
//  XWTableViewCell_c.m
//  网易新闻
//
//  Created by dllo on 15/9/21.
//  Copyright (c) 2015年 Lx. All rights reserved.
//

#import "XWTableViewCell_c.h"
#import "SDWebImage/UIImageView+WebCache.h"
#import "Settings.h"
@interface XWTableViewCell_c()
@property(nonatomic, retain)UILabel *lab1;
@property(nonatomic, retain)UIImageView *lab2_a;
@property(nonatomic, retain)UIImageView *lab2_b;
@property(nonatomic, retain)UIImageView *lab2_c;
@property(nonatomic, retain)UILabel *lab3;
@end
@implementation XWTableViewCell_c
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.selectedBackgroundView = [[[UIView alloc] initWithFrame:self.frame] autorelease];
        self.selectedBackgroundView.backgroundColor = [[Settings shareSettings]color:GrayToBlack];
        
        self.lab1 = [[UILabel alloc]init];
        self.lab1.textColor = [[Settings shareSettings]color:BlackToWhite];
        [self.contentView addSubview:_lab1];
        [_lab1 release];
        self.lab2_a = [[UIImageView alloc]init];
        self.lab2_a.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_lab2_a];
        [_lab2_a release];
        self.lab2_b = [[UIImageView alloc]init];
        self.lab2_b.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_lab2_b];
        [_lab2_b release];
        self.lab2_c = [[UIImageView alloc]init];
        self.lab2_c.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_lab2_c];
        [_lab2_c release];
        self.lab3 = [[UILabel alloc]init];
        self.lab3.textColor = [UIColor lightGrayColor];
        self.lab3.font = [UIFont systemFontOfSize:14];
        self.lab3.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_lab3];
        [_lab3 release];
        
        [self notificationHandle];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.lab1.frame = CGRectMake(10, 10, 285, 20);
    self.lab2_a.frame = CGRectMake(9, 35, 113, 85);
    self.lab2_b.frame = CGRectMake(131, 35, 113, 85);
    self.lab2_c.frame = CGRectMake(253, 35, 113, 85);
    self.lab3.frame = CGRectMake(295, 15, 70, 15);
}

- (void)setMod:(XinwenModel *)mod{
    if (_mod != mod) {
        [_mod release];
        _mod = [mod retain];
    }
    self.height = 130;
    
    self.lab1.text= mod.title;
    [self.lab2_a sd_setImageWithURL:mod.imgsrc placeholderImage:nil];
    [self.lab2_b sd_setImageWithURL:[mod.imgextra[0]objectForKey:@"imgsrc"] placeholderImage:nil];
    [self.lab2_c sd_setImageWithURL:[mod.imgextra[1]objectForKey:@"imgsrc"] placeholderImage:nil];
    self.lab3.text = [NSString stringWithFormat:@"%ld跟帖", mod.replyCount];
}

- (void)notificationHandle{
    [[NSNotificationCenter defaultCenter]addObserverForName:@"changeBackgroundColor" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
        self.backgroundColor = [[Settings shareSettings]color:WhiteToGray];
        self.lab1.textColor = [[Settings shareSettings]color:BlackToWhite];
        self.selectedBackgroundView.backgroundColor = [[Settings shareSettings]color:GrayToBlack];
    }];
}

- (void)dealloc{
    [_lab1 release];
    [_lab2_a release];
    [_lab2_b release];
    [_lab2_c release];
    [_lab3 release];
    [super dealloc];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

